package com.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Component("myAspect")
@Aspect
public class MyAspect {

    @Before("execution(* com.aop.Target.*(..))")
    public void before(){
        System.out.println("前置增强");
    }
    @After("execution(* com.aop.Target.*(..))")
    public void after(){
        System.out.println("后置增强");
    }
    @Around("execution(* com.aop.Target.*(..))")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕通知");
        Object[] args = joinPoint.getArgs();//获取请求参数
        Object proceed = joinPoint.proceed(args);//调用源方法
        System.out.println("环绕通知");
        // ProceedingJoinPoint 环绕通知中使用的获取原方法的参数
        //getArgs()获取原方法请求执行时传入的参数
        //proceed(args)调用执行原方法传入参数
        return proceed;
    }


}
